"""
缓存数据
"""
import redis
from pymysqlutil import MysqlUtil

mysqlutil = MysqlUtil("db_qiku")
# 批量插入10000条数据
# sql = 'insert into tb_content(userid, content) values(%s, %s)'
# for i in range(1, 10001):
#     args = (i, '评论内容'+str(i))
#     print(args)
#     mysqlutil.operator_data(sql, args)

# 获取数据存放到redis数据库中 类型：(userid, content) 存放到表中
sql = 'select userid, content from tb_content'
datas = mysqlutil.query_all(sql)
# 链接redis数据库
client = redis.StrictRedis(password=123456)

for data in datas:
    print(data, type(str(data)))
    client.rpush('tb_content', str(data))
# 查询数据
# result = client.lrange('tb_content', 20, 29)
# print("获取的分页的最后一夜的数据", result)
# for rt in result:
#     print(rt.decode())

# 释放资源
client.close()

